package com.example.demo.common.msg.disruptor;

import com.example.demo.common.msg.vo.MessageType;
import com.lmax.disruptor.EventTranslatorTwoArg;
import com.lmax.disruptor.RingBuffer;


public class MessageEventPublisher {

  private final RingBuffer<MessageEvent> ringBuffer;

  private static final EventTranslatorTwoArg<MessageEvent , MessageType,MessageEventVo> TRANSLATOR =
          (event, sequence, type,messageEventVo) -> {event.setMessageType(type);event.setMessageEventVo(messageEventVo);};

  public MessageEventPublisher(RingBuffer<MessageEvent> ringBuffer) {
    this.ringBuffer = ringBuffer;
  }

  public void publish(MessageType type, MessageEventVo vo ) {

    ringBuffer.publishEvent(TRANSLATOR, type,vo);

  }

}